package com.xxx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxx.pojo.Account;
import com.xxx.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/8/23 9:55
 * @Copyright 博为峰
 */
@Controller
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/queryAccountByName/{name}")
    public String queryAccountByName(@PathVariable("name") String name, ModelMap map) {
        final Account account = accountService.queryAccountByName(name);
        map.put("account", account);
        return "account";
    }

    @RequestMapping("/queryAllAccount")
    public String queryAllAccount(int pageNum, ModelMap map) {
        PageHelper.startPage(pageNum, 10);
        final List<Account> accountList = accountService.queryAllAccount();
        final PageInfo<Account> pageInfo = new PageInfo<>(accountList);
        map.put("accountList", accountList);
        map.put("pageInfo", pageInfo);
        return "account";
    }

    @RequestMapping("/queryAllAccountJson")
    @ResponseBody
    public PageInfo<Account> queryAllAccountJson(int pageNum, ModelMap map) {
        PageHelper.startPage(pageNum, 10);
        final List<Account> accountList = accountService.queryAllAccount();
        final PageInfo<Account> pageInfo = new PageInfo<>(accountList);
        return pageInfo;
    }
}
